using System;
using UnityEngine;

[Serializable]
public class Stats : MonoBehaviour
{
	public OptionsButtons3D buttons;

	public Vector2 scrollPosition;

	public int numRows;

	public Vector2 rowSize;

	public Vector2 windowMargin;

	public Vector2 listMargin;

	private Rect windowRect;

	public AudioClip clip;

	public GUISkin skin;

	public int exp;

	public string prefixE;

	public int matches;

	public string prefixMP;

	public int wins;

	public string prefixW;

	public int stopped;

	public string prefixS;

	public int time;

	public string timeS;

	public string prefixT;

	private float originalWidth;

	private float originalHeight;

	public Vector2 scale;

	public int hours;

	public int minutes;

	public int seconds;

	public int tune;

	public bool canLog;

	public float fStopThreshold;

	public float coef;

	public float smoothcoef;

	private float fResistanceFactor;

	private bool bTranslating;

	private Vector3 v3StartPos;

	private Vector3 v3LastPos;

	private Vector3 v3Delta;

	private float fStartTime;

	private float scrollPositionL;

	private float scrh;

	public Stats()
	{
		prefixE = "Exp: ";
		prefixMP = "Matches Played: ";
		prefixW = "Wins: ";
		prefixS = "Opponents Stopped: ";
		timeS = string.Empty;
		prefixT = "Time Played: ";
		originalWidth = 640f;
		originalHeight = 360f;
		tune = 100;
		fStopThreshold = 1f;
		coef = 850f;
		smoothcoef = 0.05f;
		fResistanceFactor = 0.9f;
	}

	public void CheckRes()
	{
		if (Screen.height > 700)
		{
			numRows = (int)((float)tune / ((float)Screen.height + 50f));
		}
		else
		{
			numRows = (int)((float)tune / ((float)Screen.height + 380f));
		}
		if (Screen.width > 640)
		{
			scale.x = (float)Screen.width / originalWidth;
			scale.y = (float)Screen.height / originalHeight;
		}
		else
		{
			scale.x = 1f;
			scale.y = 1f;
		}
		if (Screen.width > 1020)
		{
			scale.x = 1024f / originalWidth;
			scale.y = 600f / originalHeight;
		}
	}

	public void Start()
	{
		scrh = Screen.height;
		wins = PlayerPrefs.GetInt("Wins");
		exp = PlayerPrefs.GetInt("Exp");
		matches = PlayerPrefs.GetInt("Matches Played");
		stopped = PlayerPrefs.GetInt("Stopped");
	}

	public void checkstats()
	{
		time = (int)((float)PlayerPrefs.GetInt("Time") + Time.realtimeSinceStartup - (float)PlayerPrefs.GetInt("LastTime"));
		hours = time / 3600;
		minutes = time % 3600 / 60;
		seconds = time % 60;
		timeS = _0024"{hours:00}:{minutes:00}:{seconds:00}";
	}

	public void Update()
	{
		if (Input.GetMouseButtonDown(0))
		{
			bTranslating = false;
			v3StartPos = UnityEngine.Input.GetTouch(0).position;
			v3LastPos = v3StartPos;
			fStartTime = Time.time;
		}
		if (Input.GetMouseButtonUp(0))
		{
			v3Delta = UnityEngine.Input.GetTouch(0).position;
			if (v3Delta == v3LastPos)
			{
				v3StartPos = v3Delta;
				fStartTime = Time.time;
			}
			v3Delta = (v3Delta - v3StartPos) / (Time.time - fStartTime);
			bTranslating = true;
			if (!(Mathf.Abs(v3Delta.y) >= 300f))
			{
				v3Delta.y = 0f;
			}
		}
		if (Input.GetMouseButton(0))
		{
			Vector3 a = UnityEngine.Input.GetTouch(0).position;
			if (v3Delta == v3LastPos)
			{
				v3StartPos = UnityEngine.Input.GetTouch(0).position;
				v3LastPos = v3StartPos;
				fStartTime = Time.time;
			}
			Vector2 vector = a - v3LastPos;
			vector.x = 0f;
			vector.y /= scrh;
			scrollPosition.y += vector.y * coef;
			scrollPositionL = scrollPosition.y;
			v3LastPos = a;
		}
		if (bTranslating && !(v3Delta.magnitude <= 10f))
		{
			scrollPositionL += v3Delta.y * smoothcoef;
			v3Delta *= fResistanceFactor;
			if (!(v3Delta.magnitude >= fStopThreshold))
			{
				bTranslating = false;
			}
		}
		if (!Input.GetMouseButton(0))
		{
			scrollPosition.y = Mathf.Lerp(scrollPosition.y, scrollPositionL, Time.deltaTime * 8f);
		}
	}

	public void OnGUI()
	{
		buttons.state = true;
		GUI.skin = skin;
		windowRect = new Rect(windowMargin.x, windowMargin.y, (float)Screen.width - 2f * windowMargin.x, (float)Screen.height - 2f * windowMargin.y);
		GUI.Window(0, windowRect, DoWindow, "Stats");
	}

	public void DoWindow(int windowID)
	{
		Vector2 vector = new Vector2(windowRect.width - 2f * listMargin.x, windowRect.height - 2f * listMargin.y);
		Rect position = new Rect(listMargin.x, listMargin.y, vector.x, vector.y);
		Rect viewRect = new Rect(0f, 0f, rowSize.x, (float)numRows * rowSize.y);
		GUILayout.BeginArea(new Rect((float)Screen.width - 235f * (scale.x * 0.7f), 15f * scale.y, 120f * scale.x, 120f * scale.y));
		GUILayout.EndArea();
		scrollPosition = GUI.BeginScrollView(position, scrollPosition, viewRect, alwaysShowHorizontal: false, alwaysShowVertical: false);
		GUI.contentColor = new Color(0f, 0.69f, 1f);
		GUI.contentColor = Color.white;
		GUILayout.Label(string.Empty);
		GUILayout.Label(prefixE + exp);
		GUILayout.Label(prefixMP + matches);
		GUILayout.Label(prefixW + wins);
		GUILayout.Label(prefixS + stopped);
		GUILayout.Label(prefixT + timeS);
		if (GUILayout.Button("Close", GUILayout.Width(200f * scale.x), GUILayout.Height(30f * scale.y)))
		{
			AudioSource.PlayClipAtPoint(clip, Camera.main.transform.position);
			buttons.state = false;
			gameObject.SetActive(false);
		}
		GUI.EndScrollView();
	}

	public void Main()
	{
		InvokeRepeating("checkstats", 0f, 1f);
		InvokeRepeating("CheckRes", 0f, 0.3f);
	}
}
